﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RRRSRoguelike.Enums;
using RRRSRoguelike.Helpers;
using System.Drawing;

namespace RRRSRoguelike.Managers
{
    /// <summary>
    /// Stores a list of actions along with the keys mapped to those actions
    /// Checks action map against the inputmanager
    /// </summary>
    public class ActionManager
    {

        #region variables
        public ActionMap[] ActionMap;
        public Dictionary<string, Point> DirectionVectors;
        InputManager InputManager = GameManager.Instance.InputManager;
        #endregion

        #region methods
        public void Initialize(int numberOfActions)
        {
            ActionMap = new ActionMap[numberOfActions];
            for (int i = 0; i < numberOfActions; i++)
                ActionMap[i] = new ActionMap();

            SetupDirectionVectors();
        }

        public void SetButtons(Actions Action, ConsoleKey Key)
        {
            ActionMap[(int)Action].ConsoleKeys.Add(Key);
        }

        public bool IsActionPushed(Actions Action)
        {
            for (int i = 0; i < ActionMap[(int)Action].ConsoleKeys.Count(); i++)
            {
                if (InputManager.KeyPush(ActionMap[(int)Action].ConsoleKeys[i]))
                {
                    return true;
                }
            }
            return false;
        }

        //public bool IsActionReleased(Actions Action)
        //{
        //    for (int i = 0; i < ActionMaps[(int)Action].ConsoleKeys.Count(); i++)
        //    {
        //        if (InputManager.KeyReleased(ActionMaps[(int)Action].ConsoleKeys[i]))
        //        {
        //            return true;
        //        }
        //    }
        //    return false;
        //}

        //public bool IsActionDown(Actions Action) 
        //{
        //    for (int i = 0; i < ActionMaps[(int)Action].ConsoleKeys.Count(); i++) 
        //    {
        //        if (InputManager.KeyDown(ActionMaps[(int)Action].ConsoleKeys[i]))
        //        {
        //            return true;
        //        }
        //    }
        //    return false;
        //}

        private void SetupDirectionVectors()
        {
            DirectionVectors = new Dictionary<string, Point>();
            DirectionVectors.Add(Direction.N.ToString(), new Point(0, -1));
            DirectionVectors.Add(Direction.NE.ToString(), new Point(1, -1));
            DirectionVectors.Add(Direction.E.ToString(), new Point(1, 0));
            DirectionVectors.Add(Direction.SE.ToString(), new Point(1, 1));
            DirectionVectors.Add(Direction.S.ToString(), new Point(0, 1));
            DirectionVectors.Add(Direction.SW.ToString(), new Point(-1, 1));
            DirectionVectors.Add(Direction.W.ToString(), new Point(-1, 0));
            DirectionVectors.Add(Direction.NW.ToString(), new Point(-1, -1));
        }


        #endregion

    }

}
